package com.liliudong.template.biz.mapper.sys;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liliudong.template.common.annotation.DataScope;
import com.liliudong.template.common.entity.sys.SysUser;
import com.liliudong.template.common.vo.sys.SysUserPageVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * sys用户映射器
 *
 * @author ldli5
 * @date 2024/6/18-13:51
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {

	/**
	 * 按id选择忽略数据权限
	 *
	 * @param userId 用户id
	 * @return {@link SysUser }
	 */
	@InterceptorIgnore(dataPermission = "true")
	@Select("select * from sys_user where id = #{userId} and deleted = 0")
	SysUser selectByIdIgnoreDataPermission(long userId);

	/**
	 * 按用户名选择忽略数据权限
	 *
	 * @param username 用户名
	 * @return {@link SysUser }
	 */
	@InterceptorIgnore(dataPermission = "true")
	@Select("select * from sys_user where username = #{username} and deleted = 0")
	SysUser selectByUsernameIgnoreDataPermission(String username);

	/**
	 * 查询展开页面
	 *
	 * @param page 页
	 * @return {@link Page }<{@link SysUser }>
	 */
	@DataScope(tableAlias = "su")
	Page<SysUserPageVO> selectExpandPage(IPage<SysUser> page);
}
